﻿Imports WeifenLuo.WinFormsUI.Docking

Public Class DownloadSkinsBeForm
  Inherits DockContent

  Private _service_manager As ServiceManager = ServiceManager.GetServiceManager
  Private _il As New ImageList
  Private _config As Configuration = Configuration.GetObject

  Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
    If LinkTextBox.Text <> "" Then
      Dim file As String = LinkTextBox.Text.Split("//")(4)
      Dim name As String = LinkTextBox.Text.Split("//")(3)
      Dim file_splitted() As String = file.Replace(name & "-", "").Split("-")
      Dim resolution As String = file_splitted(0)
      Dim orgaid As String = file_splitted(1).Split(".")(0)
      Dim dw As DownloadabeWallpaper = ServiceManager.GetServiceManager.GetWallpaperService.GetNewDownloadableWallpaper()
      dw.Filename = file
      dw.Name = name
      dw.Resolution = resolution
      dw.OrgaID = orgaid
      dw.URL = LinkTextBox.Text
      If _service_manager.GetWallpaperService.CheckOrgaIDexists(dw.OrgaID, dw.Resolution) Then
        MsgBox("Die Datei existiert bereits.", MsgBoxStyle.Critical, "Warnung!")
        Me.LinkTextBox.Text = ""
      Else
        dw.DownloadFile()
        _il.Images.Add(dw.Filename, Image.FromFile(_config.SkinsPath & dw.Filename))
        Dim lvi As ListViewItem = HistoryListView.Items.Add(dw.FullName, dw.Filename)
        lvi.SubItems.Add(dw.Filename)
        lvi.SubItems.Add(dw.Resolution)
        lvi.SubItems.Add(dw.URL)
        LinkTextBox.Text = ""
        Refresh()
      End If
    End If

  End Sub

  Private Sub DownloadSkinsBeForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    HistoryListView.LargeImageList = _il
    HistoryListView.SmallImageList = _il
  End Sub
End Class